<form action="${ctx}/cardtype/manageform" method="post" id="addCardtype" enctype="multipart/form-data" class="change-error-two-box">
	<input type="hidden" name="cardId" value="${cardType.cardId!}" />

	<div class="form-group form-inline row">
		<div class="col-sm-6">
			<label><span style="color: red">*</span>卡券名称：</label>
			<input class="form-control" type="text" name="cardName" required maxlength="50" />
		</div>
	</div>

	<div class="form-group form-inline row">
		<div class="col-sm-12">
			<label style="float: left;"><span style="color: red">*</span>使用用途：</label>
			<input type="hidden" name="cardUse" />
			<div style="margin-left: 120px;">
				<#list cardUseMap as key, value>
					<#if cardType.cardUse?? && key == cardType.cardUse?c>
						<label><input type="checkbox" name="cardUseEach" value="${key}" checked="checked">${value}</label>
					<#else>
						<label><input type="checkbox" name="cardUseEach" value="${key}">${value}</label>
					</#if> 
				</#list>
			</div>
			<div id="cardUseError" class="autowidth hide" style="display: block;border-radius: 3px;background-color: #dd4b39 !important;color: #fff !important;border-color: #d73925;border: 1px solid transparent;">至少选择一项</div>
		</div>
	</div>
	
	<div class="form-group form-inline row">
		<div class="col-sm-6">
			<label><span style="color: red">*</span>折扣类型:</label>
			<#if cardType.preferentialType??>
				<label class="radio-inline"><input type="radio" name="preferentialType"  value="1" <#if cardType.preferentialType?? && cardType.preferentialType = 1>checked</#if> > 打折</label>
				<label class="radio-inline"><input type="radio" name="preferentialType"  value="2" <#if cardType.preferentialType?? && cardType.preferentialType = 2>checked</#if> > 抵扣</label>
			<#else>
				<label class="radio-inline"><input type="radio" name="preferentialType"  value="1" checked > 打折</label>
				<label class="radio-inline"><input type="radio" name="preferentialType"  value="2" > 抵扣</label>
			</#if>
		</div>
	</div>
	<div class="form-group form-inline row" id="preferentialIntensityDiv">
		<div class="col-sm-6 preferentialIntensityEach">
			<label><span style="color: red">*</span>打折/抵扣金额:</label>
			<input class="form-control" type="number" name="preferentialIntensity" required maxlength="10" value="${cardType.preferentialIntensity!}" /> 折
		</div>
		<div class="col-sm-6 preferentialIntensityEach hide">
			<label><span style="color: red">*</span>打折/抵扣金额:</label>
			<input class="form-control" type="number" name="preferentialIntensity" required maxlength="10" value="${cardType.preferentialIntensity!}" /> 元
		</div>
	</div>
	<div class="form-group form-inline row">
		<div class="col-sm-6">
			<label><span style="color: red">*</span>使用期限(天):</label>
			<input class="form-control" type="number" name="useDuration" required digits="true" maxlength="10" value="${cardType.useDuration!}"/>
			<span style=" margin-left: 5px; color: #999;">0为无期限</span>
		</div>
	</div>
	<div class="form-group form-inline row">
		<div class="col-sm-12">
			<label>卡券说明:</label>
			<textarea class="form-control" rows="3" name="cardDesc" style="width:400px;max-width:600px;max-height: 600px;" maxlength="1000">${cardType.cardDesc!}</textarea>
		</div>
	</div>
</form>

<script type="text/javascript">
	$("#addCardtype").validate();
	
	function cardUseCheckedCount() {
		var checkedCount = $("#addCardtype :checkbox:checked").length;
		return checkedCount;
	}
	
	function cardUseShowError() {
		$("#cardUseError").show();
		$("#cardUseError").removeClass("hide");
	}
	function cardUseHideError() {
		$("#cardUseError").hide();
	}

	/* 使用用途点击后更新验证提示 */
	$(':checkbox[name="cardUseEach"]').click(function(){
		var $checkeds = $("#addCardtype :checkbox:checked");
		if( $checkeds.length > 0) {
			cardUseHideError();
		} else {
			cardUseShowError();
		}
		
		var v = ',';
		for (var i = 0; i < $checkeds.length; i++) {
			v += $checkeds.eq(i).val() + ',';
		}
		console.log(v);
		$(':input[name="cardUse"]').val(v);
	});

	/* 切换折扣类型 */
	$(':radio[name="preferentialType"]').change(function(){
		var preferentialType = $(this).val();
		if(preferentialType == 1) {
			$("#preferentialIntensityDiv .preferentialIntensityEach").eq(0).show();
			$("#preferentialIntensityDiv .preferentialIntensityEach").eq(0).removeClass("hide");
			$("#preferentialIntensityDiv .preferentialIntensityEach").eq(1).hide();
			
			$("#preferentialIntensityDiv .preferentialIntensityEach").eq(0).find(":input").removeAttr("disabled");
			$("#preferentialIntensityDiv .preferentialIntensityEach").eq(1).find(":input").attr("disabled","disabled");
		} else {
			$("#preferentialIntensityDiv .preferentialIntensityEach").eq(0).hide();
			$("#preferentialIntensityDiv .preferentialIntensityEach").eq(1).removeClass("hide");
			$("#preferentialIntensityDiv .preferentialIntensityEach").eq(1).show();
			
			$("#preferentialIntensityDiv .preferentialIntensityEach").eq(0).find(":input").attr("disabled","disabled");
			$("#preferentialIntensityDiv .preferentialIntensityEach").eq(1).find(":input").removeAttr("disabled");
		}
	});
	
</script>
